package com.itheima.pojo;

import com.itheima.utils.MybatisUtils;
import generator.mapper.CustomerMapper;
import generator.pojo.Customer;
import org.apache.ibatis.session.SqlSession;
import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

public class CustomerTest {
    @Test
    public void findCustomerByNameAndJobsTest () {
        SqlSession sqlSession = MybatisUtils.getSession();
        Customer customer = new Customer();
        customer.setUsername("jack");
        customer.setJabs("teacher");
        List<Customer>customers = sqlSession.selectList("com.itheima.pojo.findCustomerByNameAndJobs",customer);
        for (Customer cust : customers) {
            System.out.println(cust);
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findCustomerByTest () {
        SqlSession sqlSession = MybatisUtils.getSession();
        Customer customer = new Customer();
        customer.setId(3);
        customer.setPhone("154454898198");
        customer.setUsername("jack");
        int rows = sqlSession.update("com.itheima.pojo.updateByPrimaryKeySelective",customer);
        if (rows > 0) {
            System.out.println("成功");
        }
        else {
            System.out.println("失败");
        }
        sqlSession.commit();
        sqlSession.close();
    }
    @Test
    public void findByArrayTest () {
        SqlSession sqlSession = MybatisUtils.getSession();
        Integer [] roleIds = {2,3};
        List<Customer> customers = sqlSession.selectList("com.itheima.pojo.findByArray",roleIds);
        for (Customer customer : customers) {
            System.out.println(customer);
        }
        sqlSession.close();
    }
    @Test
    public void findByListTest () {
        SqlSession Session = MybatisUtils.getSession();
        List<Integer> ids = new ArrayList<Integer>();
        ids.add(1);
        ids.add(2);
        List<Customer> customers = Session.selectList("com.itheima.pojo.findByList",ids);
        for (Customer customer : customers) {
            System.out.println(customer);
        }
        Session.close();
    }
}
